<template>
  <uni-nav-bar title="仓库列表" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
  <scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="scroll-box"
    :style="{ height: pageHeight + 'px' }">
    <view class="package_sale space-between" style="min-height:100rpx" v-for="item in wareAll" :key="item.id"
      @click="navTo('Sale/warehouse/houseDeatil?id='+item.id)">
      <view>{{item.name}}</view>
      <uni-icons type="forward" size="20"></uni-icons>
    </view>
    <Popu v-if="wareAll.length<1" :pageHeight="pageHeight" text="暂无仓库列表"></Popu>
  </scroll-view>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import { navBack, navTo } from '@/utils/navigator';
  import Popu from '@c/earthPushing/common/popu.vue';
  import { getKuList } from '@/gql/earthPushing/warehouse';
  import { showLoading } from '@/utils/prompt';
  import { toPublish } from '@mqtt';
  import { getDriverID } from '@/stores/driverID';
  const staff_id = getDriverID();
  const pageHeight = ref();
  const wareAll = ref([])
  const lastPage = ref(1);
  const currentPage = ref(1);
  uni.getSystemInfo({
    success: function (res) {
      pageHeight.value = res.windowHeight - 120;
    },
  });
  /**
   * 获取仓库信息
   * @param {Number} page  获取仓库列表数据
   * @param {String} keywords  搜索信息
   */
  wareList()
  function wareList() {
    showLoading()
    const payload = {
      query: getKuList,
      variables: {
        page: currentPage.value,
        staff_id
      },
    };
    toPublish(
      'ql/staff/getKuList',
      payload,
      (obj : any) => {
        const { getKuList } = obj.data;
        wareAll.value = [...wareAll.value, ...getKuList.list];
        lastPage.value = getKuList.lastpage;
      }
    );
  }
  /**
   * 加载更多
   */
  function loadMore() {
    if (currentPage.value < lastPage.value) {
      currentPage.value++;
      wareList();
    }
  }
</script>

<style scoped lang="less">
</style>